package teamroute

import (
	"itodo/core/dao/teamdao"
	"itodo/core/localwrap"
	"itodo/core/service/teams"
	"itodo/http/routes"

	"github.com/RocksonZeta/irisx"
	"github.com/kataras/iris/v12"
)

var logTasks = localwrap.GetLogger().Fork("itodo/http/teamroute", "RouteTasks")

//Route{serviceName} 
func RouteTasks(party iris.Party) {
	party.Get("/", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		id := c.CheckQuery("id").NotEmpty().Int(0)
		uid := c.GetUidInt()
		logTasks.Debug().Str("path", c.Path()).Int("id", id).Int("uid", uid).Send()
		r := teams.Tasks{}.Get(id)
		c.Ok(r)
	})
	party.Get("/list", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		uid := c.GetUidInt()
		logTasks.Debug().Str("path", c.Path()).Int("uid", uid).Send()
		r := teams.Tasks{}.ListByUid(uid)
		c.Ok(r)
	})
	party.Post("/update", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		var param teamdao.TasksUpdateParam
		param.Id = c.CheckBody("id").NotBlank().Int(0)
		param.Name = c.CheckBody("name").NotBlank().String()
		logTasks.Debug().Str("path", c.Path()).Interface("param", param).Send()
		routes.Check(c)
		teams.Tasks{}.Update(param)
		c.Ok(nil)
	})
	party.Post("/delete", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		id := c.CheckBody("id").NotBlank().Int(0)
		logTasks.Debug().Str("path", c.Path()).Int("uid", c.GetUidInt()).Send()
		routes.Check(c)
		teams.Tasks{}.Delete(id)
		c.Ok(nil)
	})
}
